package com.gmss.crawler.module.person.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gmss.crawler.enums.AcademicianEnum;
import com.gmss.crawler.module.company.domain.Company;
import com.gmss.crawler.module.company.service.ICompanyService;
import com.gmss.crawler.module.honor.domain.Honor;
import com.gmss.crawler.module.honor.service.IHonorService;
import com.gmss.crawler.module.paper.domain.Paper;
import com.gmss.crawler.module.paper.service.IPaperService;
import com.gmss.crawler.module.person.domain.PersonInfo;
import com.gmss.crawler.module.person.mapper.PersonInfoMapper;
import com.gmss.crawler.module.person.service.IPersonInfoService;
import com.gmss.crawler.module.resume.domain.Resume;
import com.gmss.crawler.module.resume.service.IResumeService;
import com.gmss.crawler.module.social.domain.Social;
import com.gmss.crawler.module.social.service.ISocialService;
import com.gmss.crawler.module.title.domain.PersonTitle;
import com.gmss.crawler.module.title.service.IPersonTitleService;
import com.gmss.crawler.utils.CommonUtils;
import com.gmss.crawler.utils.CrawlerCommonUtils;
import com.gmss.crawler.utils.ExcelUtils;
import com.gmss.crawler.utils.RegexUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/**
 * <p>
 * 人员信息 服务实现类
 * </p>
 *
 * @author Auto-generator
 *
 */
@Service
public class PersonInfoServiceImpl extends ServiceImpl<PersonInfoMapper, PersonInfo> implements IPersonInfoService {

    @Resource
    private PersonInfoMapper personInfoMapper;

    @Resource
    private IPersonTitleService iPersonTitleService;

    @Resource
    private ICompanyService iCompanyService;

    @Resource
    private IHonorService iHonorService;

    @Resource
    private IResumeService iResumeService;

    @Resource
    private ISocialService iSocialService;

    @Resource
    private IPaperService iPaperService;

    @Value("${img_file_path}")
    private String imgFilePath;

    /**
     * 查询人员所在单位是否存在
     * 存在获取company_id
     * 不存在保存所在单位信息
     *
     * @param personInfo
     */
    public void queryCompany(PersonInfo personInfo) {
        if (StringUtils.isNotBlank(personInfo.getWorkCompany()) && personInfo.getCompanyId() == null) {
            final LambdaQueryWrapper<Company> lambda2 = new QueryWrapper<Company>().lambda();
            lambda2.eq(Company::getCompanyName, personInfo.getWorkCompany().trim());
//            lambda2.like(Company::getCompanyName, personInfo.getWorkCompany().trim());
            List<Company> list1 = iCompanyService.list(lambda2);
            if (CollectionUtils.isNotEmpty(list1)) {
                personInfo.setCompanyId(list1.get(0).getId());
            } else {
                Company company = new Company();
                if (StringUtils.isNotBlank(personInfo.getWorkCompany())) {
                    company.setCompanyName(personInfo.getWorkCompany());
                }
                if (null != personInfo.getCompanyType()) {
                    company.setCompanyType(personInfo.getCompanyType());
                }
                if (StringUtils.isNotBlank(personInfo.getCompanyAddress())) {
                    company.setAddress(personInfo.getCompanyAddress());
                }
                iCompanyService.save(company);
                personInfo.setCompanyId(company.getId());
            }
        }
    }

    /**
     * 查询人员信息与单位所在地
     *
     * @param queryMap
     * @return
     */
    @Override
    public List<PersonInfo> queryPersonInfoAndCompany(Map<String, Object> queryMap) {
        return personInfoMapper.queryPersonInfoAndCompany(queryMap);

    }

    @Override
    public List<PersonInfo> queryExportExcelData(Map<String, Object> queryMap) {
        List<PersonInfo> list = personInfoMapper.queryExportExcelData(queryMap);
        getDetailData(queryMap, list);

        return list;
    }

    @Override
    public void getDetailData(Map<String, Object> queryMap, List<PersonInfo> list) {
        // 查询人员的专利总数
        List<Map> patentList = patentCount(queryMap);
//        // 查询人员的出版物总数
        List<Map> publicationList = publicationCount(queryMap);
        if (CollectionUtils.isNotEmpty(list)) {
            for (PersonInfo personInfo : list) {
                Integer paperCountNum = paperCount(personInfo.getId());
                if (null == paperCountNum)
                    personInfo.setPaperCount("0");
                else
                    personInfo.setPaperCount(paperCountNum.toString());

                AtomicReference<String> patentCount = new AtomicReference<>("0");
                if (CollectionUtils.isNotEmpty(patentList)) {
                    for (Map map : patentList) {
                        if (MapUtils.isNotEmpty(map)) {
                            if (StringUtils.equals(map.get("personId").toString(), personInfo.getId().toString())) {
                                patentCount.set(map.get("patentCount").toString());
                                break;
                            }
                        }
                    }
                }
                AtomicReference<String> publicationCount = new AtomicReference<>("0");
                if (CollectionUtils.isNotEmpty(publicationList)) {
                    for (Map map : publicationList) {
                        if (MapUtils.isNotEmpty(map)) {
                            if (StringUtils.equals(map.get("personId").toString(), personInfo.getId().toString())) {
                                publicationCount.set(map.get("publicationCount").toString());
                                break;
                            }
                        }
                    }
                }

                String honorOne = getHonorData(personInfo, 0);
                if (StringUtils.isNotBlank(honorOne)) {
                    personInfo.setScientificResearchAwards(honorOne);
                }
                String honorTwo = getHonorData(personInfo, 1);
                if (StringUtils.isNotBlank(honorTwo)) {
                    personInfo.setHonor(honorTwo);
                }
                String resumeStr = getResumeData(personInfo);
                if (StringUtils.isNotBlank(resumeStr)) {
                    personInfo.setResume(resumeStr);
                }
                String socialStr = getSocialData(personInfo);
                if (StringUtils.isNotBlank(socialStr)) {
                    personInfo.setSocialService(socialStr);
                }
                personInfo.setPatentCount(patentCount.get());
                personInfo.setPublicationCount(publicationCount.get());
            }
        }
    }

    private String getSocialData(PersonInfo personInfo) {
        LambdaQueryWrapper<Social> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Social::getPersonId, personInfo.getId());
        List<Social> socialList = iSocialService.list(lambdaQueryWrapper);
        if (CollectionUtils.isNotEmpty(socialList)) {
            List<String> list = new ArrayList<>();
            socialList.forEach(social -> {
                StringBuilder sb = new StringBuilder();
                if (StringUtils.isNotBlank(social.getTenure())) {
                    sb.append(social.getTenure()).append("-");
                }
                if (StringUtils.isNotBlank(social.getDuties())) {
                    sb.append(social.getDuties()).append("。");
                }
                list.add(sb.toString());
            });
            if (CollectionUtils.isNotEmpty(list))
                return StringUtils.join(list, " ");
        }
        return null;
    }

    private String getResumeData(PersonInfo personInfo) {
        LambdaQueryWrapper<Resume> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Resume::getPersonId, personInfo.getId());
        List<Resume> resumeList = iResumeService.list(lambdaQueryWrapper);

        if (CollectionUtils.isNotEmpty(resumeList)) {
            List<String> list = new ArrayList<>();
            resumeList.forEach(resume -> {
                StringBuilder sb = new StringBuilder();
                if (StringUtils.isNotBlank(resume.getResumeDate())) {
                    sb.append(resume.getResumeDate()).append("-");
                }
                if (StringUtils.isNotBlank(resume.getResume())) {
                    sb.append(resume.getResume()).append("。");
                }
                list.add(sb.toString());
            });
            if (CollectionUtils.isNotEmpty(list))
                return StringUtils.join(list, " ");
        }

        return null;
    }

    /**
     * @param personInfo
     * @param type       类型 0：科研成果；1：荣誉表彰；
     */
    private String getHonorData(PersonInfo personInfo, Integer type) {
        LambdaQueryWrapper<Honor> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Honor::getPersonId, personInfo.getId());
        lambdaQueryWrapper.eq(Honor::getType, type);
        List<Honor> honorList = iHonorService.list(lambdaQueryWrapper);

        if (CollectionUtils.isNotEmpty(honorList)) {
            List<String> list = new ArrayList<>();
            honorList.forEach(honor -> {
                StringBuilder sb = new StringBuilder();
                if (StringUtils.isNotBlank(honor.getHonorDate())) {
                    sb.append(honor.getHonorDate()).append("-");
                }
                if (StringUtils.isNotBlank(honor.getPrizeName()) && type == 0) {
                    sb.append(honor.getPrizeName()).append("。");
                } else if (StringUtils.isNotBlank(honor.getPrizeName()) && type == 1) {
                    if (StringUtils.isNotBlank(honor.getIssueCompany())) {
                        sb.append(honor.getPrizeName()).append("-").append("颁发单位：").append(honor.getIssueCompany()).append("。");
                    } else {
                        sb.append(honor.getPrizeName()).append("。");
                    }
                }
                list.add(sb.toString());
            });
            if (CollectionUtils.isNotEmpty(list))
                return StringUtils.join(list, " ");
        }

        return null;
    }

    private Integer paperCount(Long personId) {
        LambdaQueryWrapper<Paper> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(Paper::getPersonId, personId);
        return iPaperService.count(lambdaQueryWrapper);
    }

    /**
     * 查询人员的论文总数
     *
     * @param queryMap
     * @return
     */
    @Override
    public List<Map> paperCount(Map<String, Object> queryMap) {
        return personInfoMapper.paperCount(queryMap);
    }

    /**
     * 查询人员的专利总数
     *
     * @param queryMap
     * @return
     */
    @Override
    public List<Map> patentCount(Map<String, Object> queryMap) {
        return personInfoMapper.patentCount(queryMap);
    }

    /**
     * 查询人员的出版物总数
     *
     * @param queryMap
     * @return
     */
    @Override
    public List<Map> publicationCount(Map<String, Object> queryMap) {
        return personInfoMapper.publicationCount(queryMap);
    }

    @Override
    public boolean writeExcel(String filePath, String fileName, List<PersonInfo> personInfoList) {
        if (CollectionUtils.isEmpty(personInfoList))
            return false;
        List<LinkedHashMap<String, Object>> list = convertExcel(personInfoList);
        return ExcelUtils.saveExcel(fileName, filePath, list);
    }

    @Override
    public List<PersonInfo> getUpdatePersonInfoData(JSONObject jsonObject) {

        List<PersonInfo> personInfoList = new ArrayList<>();
        String name = "";
        Integer startId = null;
        Integer endId = null;
        if (jsonObject.containsKey("name") && StringUtils.isNotBlank(jsonObject.getString("name"))) {
            name = jsonObject.getString("name");
        }
        if (jsonObject.containsKey("startId") && StringUtils.isNotBlank(jsonObject.getString("startId"))) {
            startId = jsonObject.getInteger("startId");
        }
        if (jsonObject.containsKey("endId") && StringUtils.isNotBlank(jsonObject.getString("endId"))) {
            endId = jsonObject.getInteger("endId");
        }

        String type = jsonObject.containsKey("type") ? jsonObject.getString("type") : "";
        List<Integer> list = new ArrayList<>();
        List<PersonTitle> personTitleList = new ArrayList<>();
        LambdaQueryWrapper<PersonTitle> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        switch (type) {
            case "0":
                // 院士
                list = getAcademician();
                jsonObject.put("personTitles", list);
                personInfoList = queryPersonInfoAndCompany(jsonObject);
                break;
            case "1":
                // 长江学者
                List<Integer> list2 = new ArrayList<>();
                list2.add(AcademicianEnum.CHANGJIANG_SCHOLAR_SPECIAL.getCode());
                list2.add(AcademicianEnum.CHANGJIANG_SCHOLAR_LECTURE.getCode());
                list2.add(AcademicianEnum.CHANGJIANG_SCHOLAR_YOUTH.getCode());
                jsonObject.put("personTitles", list2);
                personInfoList = queryPersonInfoAndCompany(jsonObject);
                break;
            case "2":
                break;
            case "3":
                // 百人计划
                break;
            case "4":
                break;
            default:
                personInfoList = queryPersonInfoAndCompany(jsonObject);
                break;
        }
        return personInfoList;
    }

    /**
     * 只有院士，暂时不需要其它
     *
     * @return
     */
    @Override
    public List<Integer> getAcademician() {
        List<Integer> list = new ArrayList<>();
        list.add(AcademicianEnum.CAS_ACADEMICIAN.getCode());
        list.add(AcademicianEnum.CAS_DIE_ACADEMICIAN.getCode());
        list.add(AcademicianEnum.CAS_FOREIGN_ACADEMICIAN.getCode());
        list.add(AcademicianEnum.CAS_DIE_FOREIGN_ACADEMICIAN.getCode());
        list.add(AcademicianEnum.CAE_ACADEMICIAN.getCode());
        list.add(AcademicianEnum.CAE_DIE_ACADEMICIAN.getCode());
        list.add(AcademicianEnum.CAE_FOREIGN_ACADEMICIAN.getCode());
        list.add(AcademicianEnum.CAE_DIE_FOREIGN_ACADEMICIAN.getCode());
        list.add(AcademicianEnum.TWO_CAS_CAE.getCode());
        list.add(AcademicianEnum.TWO_CAS_CAE_DIE.getCode());
        list.add(AcademicianEnum.TWO_CAS_CAE_FOREIGN.getCode());
        list.add(AcademicianEnum.TWO_CAS_CAE_DIE_FOREIGN.getCode());
        return list;
    }

    @Override
    public List<PersonInfo> customBySql(Map map) {
        return personInfoMapper.customBySql(map);
    }

    @Override
    public List<PersonInfo> customByWikiSql(Map map) {
        return personInfoMapper.customByWikiSql(map);
    }

    /**
     * 验证是否重名，并走保存或更新
     * 逻辑：
     * 根据已获取的姓名 + 工作单位名称 与 person_info表的姓名 + company表的company_name 验证，相同为同一个人，否则不是同一个人
     * 再根据已获取的姓名 + 专业 与 person_info表的姓名 + 专业 验证，相同为同一个人，否则不是同一个人
     *
     * @param list
     */
    @Override
    public void verifyDuplicateNamesAndSaveOrUpdate(List<PersonInfo> list) {
        for (PersonInfo personInfo : list) {
            PersonTitle personTitle = new PersonTitle();
            BeanUtil.copyProperties(personInfo, personTitle);
            LambdaQueryWrapper<PersonInfo> infoWrapper = new LambdaQueryWrapper<>();
            infoWrapper.eq(PersonInfo::getName, personInfo.getName());
            infoWrapper.eq(PersonInfo::getStatus, 1);
            infoWrapper.eq(PersonInfo::getDelFlag, 1);
            if (personInfo.getCompanyId() != null) {
                infoWrapper.eq(PersonInfo::getCompanyId, personInfo.getCompanyId());
            }
            List<PersonInfo> infoList = list(infoWrapper);
            if (CollectionUtils.isNotEmpty(infoList)) {
                Boolean stamp = false;
//                int num = 0;
                //如果infoTopyList不为空 说明数据库中有名字相同的人
                for (PersonInfo info : infoList) {
                    //比较工作单位
                    Long companyId = info.getCompanyId();
                    LambdaQueryWrapper<Company> companyWrapper = new LambdaQueryWrapper<>();
                    companyWrapper.eq(Company::getId, companyId);
                    Company company = iCompanyService.getOne(companyWrapper);
                    if (company != null) {
                        //如果company不为null
                        //如果单位一样   那就认为是同一个人
                        if (StringUtils.equals(company.getCompanyName(), personInfo.getWorkCompany())) {
                            stamp = getPersonTitleBoolean(personInfo, personTitle, info);
                            break;
                        } else if (StringUtils.isNotBlank(personInfo.getMajor()) && StringUtils.isNotBlank(info.getMajor()) && CommonUtils.getSimilarityRatio(info.getMajor(), personInfo.getMajor()) >= 70) {
                            //如果工作单位不同   则说明不是同一个人
                            //在info，title，company，表都存数据
                            stamp = getPersonTitleBoolean(personInfo, personTitle, info);
                            break;
                        } else {
                            stamp = false;
                        }
                    } else {
                        //如果单位不一样    专业一样  也认为是同一个人
                        if (StringUtils.isNotBlank(personInfo.getMajor()) && StringUtils.isNotBlank(info.getMajor()) && CommonUtils.getSimilarityRatio(info.getMajor(), personInfo.getMajor()) >= 70) {
                            //如果工作单位不同   则说明不是同一个人
                            //在info，title，company，表都存数据
                            stamp = getPersonTitleBoolean(personInfo, personTitle, info);
                            break;
                        } else {
                            stamp = false;
                        }
                    }
                }
                if (stamp == false) {
                    //  如果不同   说明不是一个人
                    if (StringUtils.isNotBlank(personInfo.getWorkCompany())) {
                        queryCompany(personInfo);
                    }
                    save(personInfo);
                    Long id = personInfo.getId();
                    personTitle.setPersonId(id);
                    iPersonTitleService.save(personTitle);
                } else {
                    saveOrUpdate(personInfo);
                    saveSocial(personInfo);
                    saveHonor(personInfo);
                }
            } else {
                if (StringUtils.isNotBlank(personInfo.getWorkCompany())) {
                    queryCompany(personInfo);
                }
                save(personInfo);
                saveSocial(personInfo);
                saveHonor(personInfo);
                Long id = personInfo.getId();
                personTitle.setPersonId(id);
                if (personTitle.getAcademicianTitle() != null)
                    iPersonTitleService.save(personTitle);
            }
        }

    }

    private void saveHonor(PersonInfo personInfo) {
        if (StringUtils.isNotBlank(personInfo.getHonor())) {
            LambdaQueryWrapper<Honor> honorWrapper = new LambdaQueryWrapper<>();
            honorWrapper.eq(Honor::getPersonId, personInfo.getId());
            honorWrapper.eq(Honor::getPrizeName, personInfo.getHonor());
            int count = iHonorService.count(honorWrapper);
            if (count <= 0) {
                Honor honor = new Honor().builder().personId(personInfo.getId()).type(1).prizeName(personInfo.getHonor()).build();
                iHonorService.save(honor);
            }
        }
    }

    private void saveSocial(PersonInfo personInfo) {
        if (StringUtils.isNotBlank(personInfo.getSocialService())) {
            LambdaQueryWrapper<Social> socialWrapper = new LambdaQueryWrapper<>();
            socialWrapper.eq(Social::getPersonId, personInfo.getId());
            socialWrapper.eq(Social::getDuties, personInfo.getSocialService());
            int count = iSocialService.count(socialWrapper);
            if (count <= 0) {
                Social social = new Social().builder().personId(personInfo.getId()).duties(personInfo.getSocialService()).build();
                iSocialService.save(social);
            }
        }
    }

    /**
     * 根据人员id，头衔，当选年 查询头衔表中是否存在
     *
     * @param personInfo
     * @param personTitle
     * @param info
     * @return
     */
    private Boolean getPersonTitleBoolean(PersonInfo personInfo, PersonTitle personTitle, PersonInfo info) {
        try {
            //如果相同   认为是同一个人
            //在title表中查询是否有数据
            LambdaQueryWrapper<PersonTitle> titleWrapper = new LambdaQueryWrapper<>();
            titleWrapper.eq(PersonTitle::getPersonId, info.getId());
            titleWrapper.eq(PersonTitle::getAcademicianTitle, personInfo.getAcademicianTitle());
            if (StringUtils.isNotBlank(personInfo.getElectionYear()))
                titleWrapper.eq(PersonTitle::getElectionYear, personInfo.getElectionYear());
            if (personInfo.getCaseId() != null)
                titleWrapper.eq(PersonTitle::getCaseId, personInfo.getCaseId());
            List<PersonTitle> titleList = iPersonTitleService.list(titleWrapper);
            if (CollectionUtils.isNotEmpty(titleList)) {
                personInfo.setId(info.getId());
                //如果titleList不为空  说明在title表有数据    不需要存数据库
                if (StringUtils.isNotBlank(personInfo.getImgName()) && StringUtils.containsAny(personInfo.getImgName(), "http://","https://")) {
                    CrawlerCommonUtils.getPersonalImgSave(personInfo.getImgName(), imgFilePath + "youth-img"+ File.separator, info.getId() + ".jpg");
                    personInfo.setImgName(info.getId() + ".jpg");
                }
                String links = info.getRelatedLinks();
                if (StringUtils.isNotBlank(links)) {
                    if (StringUtils.isNotBlank(personInfo.getRelatedLinks())) {
                        String youthLinks = personInfo.getRelatedLinks();
                        JSONArray youthArray = JSON.parseArray(youthLinks);
                        if (youthArray != null && youthArray.size() > 0) {
                            JSONArray array = new JSONArray();
                            try {
                                array = JSON.parseArray(links);
                            } catch (Exception e) {
                                JSONObject obj = JSON.parseObject(links);
                                array.add(obj);
                            }
                            array.addAll(youthArray);
                            personInfo.setRelatedLinks(JSON.toJSONString(array));
                        }
                    }
                }

                return true;
            } else {
                //title表中没有数据   只在title表中存入一份数据即可
                Long id = info.getId();
                personInfo.setId(id);
                personTitle.setPersonId(id);
                if (personInfo.getCaseId() != null)
                    personTitle.setCaseId(personInfo.getCaseId());
                if (personInfo.getAcademicianTitle() != null)
                    iPersonTitleService.save(personTitle);
                return true;
            }
        } catch (Exception e) {
            log.error("getPersonTitleBoolean 根据人员id，头衔，当选年 查询头衔表中是否存在 Exception :{}" ,e);
            return false;
        }
//        return stamp;
    }


    public List<LinkedHashMap<String, Object>> convertExcel(List<?> lists) {
        List<LinkedHashMap<String, Object>> rows = new ArrayList<>(lists.size());
        Object object = lists.get(0);
        if (object instanceof PersonInfo) {
            List<PersonInfo> list = (List<PersonInfo>) lists;
            list.forEach((PersonInfo personInfo) -> {
                LinkedHashMap<String, Object> row = new LinkedHashMap<>(list.size());
                row.put("唯一标识", personInfo.getId());
                row.put("姓名", StringUtils.isNotBlank(personInfo.getName()) ? personInfo.getName() : "");
                row.put("外文名", StringUtils.isNotBlank(personInfo.getForeignName()) ? personInfo.getForeignName() : "");
                row.put("个人图像", StringUtils.isNotBlank(personInfo.getImgName()) ? personInfo.getImgName() : "");
                row.put("职称", StringUtils.isNotBlank(personInfo.getPersonTitle()) ? personInfo.getPersonTitle() : "教授");
//                row.put("头衔", personInfo.getAcademicianTitle() != null ? AcademicianEnum.getEnum(personInfo.getAcademicianTitle()).getValue() : "");
                row.put("头衔", personInfo.getAcademicianTitleValue());
                row.put("学位", StringUtils.isNotBlank(personInfo.getAcademicDegree()) ? personInfo.getAcademicDegree() : "博士");
                row.put("国籍", StringUtils.isNotBlank(personInfo.getNationality()) ? personInfo.getNationality() : "");
                row.put("民族", StringUtils.isNotBlank(personInfo.getNation()) ? personInfo.getNation() : "");
                row.put("出生日期", StringUtils.isNotBlank(personInfo.getBirthday()) ? personInfo.getBirthday() : "");
                row.put("逝世日期", StringUtils.isNotBlank(personInfo.getDateOfDeath()) ? personInfo.getDateOfDeath() : "");
                row.put("出生地", StringUtils.isNotBlank(personInfo.getBirthplace()) ? personInfo.getBirthplace() : "");
                row.put("性别", StringUtils.isNotBlank(personInfo.getSex()) ? personInfo.getSex() : "");
                row.put("毕业院校", StringUtils.isNotBlank(personInfo.getSchool()) ? personInfo.getSchool() : "");
                row.put("学部", StringUtils.isNotBlank(personInfo.getDepartment()) ? personInfo.getDepartment() : "");
                row.put("专业", StringUtils.isNotBlank(personInfo.getMajor()) ? personInfo.getMajor() : "");
                row.put("所在单位", StringUtils.isNotBlank(personInfo.getWorkCompany()) ? personInfo.getWorkCompany() : "");
                row.put("单位所在地", StringUtils.isNotBlank(personInfo.getCompanyAddress()) ? personInfo.getCompanyAddress() : "");
                row.put("单位类型", StringUtils.isNotBlank(personInfo.getCompanyType()) ? personInfo.getCompanyType() : "");
                row.put("政党", StringUtils.isNotBlank(personInfo.getPoliticalParty()) ? personInfo.getPoliticalParty() : "");
                row.put("个人简介", StringUtils.isNotBlank(personInfo.getDescribeData()) ? RegexUtils.replaceData(personInfo.getDescribeData(), RegexUtils.ALL_ZHONG_REGEX, "") : "");
                row.put("个人履历", StringUtils.isNotBlank(personInfo.getResume()) ? personInfo.getResume() : "");
                row.put("社会任职", StringUtils.isNotBlank(personInfo.getSocialService()) ? personInfo.getSocialService() : "");
                row.put("研究方向", StringUtils.isNotBlank(personInfo.getResearchContents()) ? personInfo.getResearchContents() : "");
                row.put("主要成就", StringUtils.isNotBlank(personInfo.getAchievement()) ? personInfo.getAchievement() : "");
                row.put("科研奖项", StringUtils.isNotBlank(personInfo.getScientificResearchAwards()) ? personInfo.getScientificResearchAwards() : "");
                row.put("荣誉表彰", StringUtils.isNotBlank(personInfo.getHonor()) ? personInfo.getHonor() : "");
                row.put("代表作品", StringUtils.isNotBlank(personInfo.getPublicationCount()) ? personInfo.getPublicationCount() : "0");
                row.put("专利", StringUtils.isNotBlank(personInfo.getPatentCount()) ? personInfo.getPatentCount() : "0");
                row.put("论文", StringUtils.isNotBlank(personInfo.getPaperCount()) ? personInfo.getPaperCount() : "0");
                row.put("当选年", StringUtils.isNotBlank(personInfo.getElectionYear()) ? personInfo.getElectionYear() : "");
                row.put("聘任年限(0：终身，1：一年，2：两年...)", personInfo.getTitleYears());
//                row.put("相关链接", StringUtils.isNotBlank(personInfo.getRelatedLinks()) ? personInfo.getRelatedLinks() : "");
                rows.add(row);
            });
        }
        return rows;
    }
}
